package drds.server.execute_engine.data_handling;

public class AggregateFunctionType {
	public static final int COUNT = 1;
	public static final int SUM = 2;
	public static final int MIN = 3;
	public static final int MAX = 4;
	public static final int AVG = 5;
	public static final int UNSUPPORT = -1;
	public static final int NOMERGE = -2;
	public final int mergeType;
	public final Column colum;

	public AggregateFunctionType(Column colum, int mergeType) {
		super();
		this.colum = colum;
		this.mergeType = mergeType;
	}

	public static int getType(String mergeType) {
		if (mergeType.startsWith("count")) {
			return COUNT;
		} else if (mergeType.startsWith("sum")) {
			return SUM;
		} else if (mergeType.startsWith("min")) {
			return MIN;
		} else if (mergeType.startsWith("max")) {
			return MAX;
		} else if (mergeType.startsWith("avg")) {
			return AVG;
		} else {
			return UNSUPPORT;
		}
	}

	public static int tryParseAggCol(String column) {
		// MIN(*),MAX(*),COUNT(*),SUM
		if (column.length() < 6) {
			return -1;
		}

		if (column.startsWith("count(")) {
			return COUNT;
		} else if (column.startsWith("sum(")) {
			return SUM;
		} else if (column.startsWith("min(")) {
			return MIN;
		} else if (column.startsWith("max(")) {
			return MAX;
		} else if (column.startsWith("avg(")) {
			return AVG;
		} else {
			return NOMERGE;
		}
	}
}